package com.jzsk.variable.center.zhengxin.zxtzys.rules;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.NumberUtil;
import com.jzsk.variable.center.zhengxin.zxtzys.Feature;
import com.jzsk.variable.center.zhengxin.zxtzys.bean.Document;
import com.jzsk.variable.center.zhengxin.zxtzys.bean.PC05;
import com.jzsk.variable.center.zhengxin.zxtzys.bean.PC05B;
import com.jzsk.variable.center.zhengxin.zxtzys.bean.PQO;
import com.jzsk.variable.center.zhengxin.zxtzys.constants.Constants;

import java.util.Optional;

public class FeatureR00001 implements Feature {

    @Override
    public String parse(Document document) {
        try {
            String pc05bs01 = Optional.ofNullable(document)
                    .map(Document::getPQO)
                    .map(PQO::getPC05)
                    .map(PC05::getPC05B)
                    .map(PC05B::getPC05BS01).orElse(Constants.STR_MINUS_1);
            return mapping1(pc05bs01);
        } catch (Exception e) {
            return Constants.STR_MINUS_1;
        }

    }

    private String mapping1(String str) {
        if (CharSequenceUtil.isEmpty(str) || Constants.STR_MINUS_1.equals(str) || !NumberUtil.isNumber(str)) {
            return Constants.STR_MINUS_1;
        }

        int i = Integer.parseInt(str);

        if (i == 0) {
            return Constants.STR_NUMBER_1;
        } else if (i == 1) {
            return Constants.STR_NUMBER_2;
        } else if (i >= 2 && i <= 3) {
            return Constants.STR_NUMBER_3;
        } else if (i >= 4 && i <= 5) {
            return Constants.STR_NUMBER_4;
        } else if (i >= 6 && i <= 8) {
            return Constants.STR_NUMBER_5;
        } else if (i >= 9 && i <= 11) {
            return Constants.STR_NUMBER_6;
        } else if (i >= 12 && i <= 13) {
            return Constants.STR_NUMBER_7;
        } else if (i >= 14 && i <= 24) {
            return Constants.STR_NUMBER_8;
        } else if (i >= 25 && i <= 30) {
            return Constants.STR_NUMBER_9;
        } else if (i >= 31 && i <= 35) {
            return Constants.STR_NUMBER_10;
        } else {
            return Constants.STR_NUMBER_11;
        }
    }

}
